import 'package:flutter/material.dart';

class MyCheckBox extends StatelessWidget{
  bool _selectValue=false;
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("复选框&单选框&开关"),
      ),
      body: Container(
        alignment: Alignment.center,
        padding: EdgeInsets.only(left: 20,right: 20),
        child: Column(
          children: <Widget>[
            myCheckBox(),
            myRadio(),
            mySwitch(),
            mySlide()
          ],
        )
      )

    );
  }
}
class myCheckBox extends StatefulWidget{
  @override
    myCheckBoxState createState() {
      // TODO: implement createState
      return myCheckBoxState();
    }
}
class myCheckBoxState extends State<myCheckBox>{
  bool _checkValue=false;
  @override
    Widget build(BuildContext context) {
      // TODO: implement build
      return CheckboxListTile(
        value: _checkValue,
        onChanged: (value){
          setState(() {
                    _checkValue=value;  
                    print(value);
                    });
        },
        title: Text("完成日常任务"),
        subtitle: Text("特殊任务除外"),
        secondary: Icon(Icons.text_rotation_angledown),
        activeColor: Colors.greenAccent,
        selected: _checkValue,
      );
    }
}
class myRadio extends StatefulWidget{
  @override
    myRadioState createState() {
      // TODO: implement createState
      return myRadioState();
    }
}
class myRadioState extends State<myRadio>{
  int _radioValue=1;
  @override
    Widget build(BuildContext context) {
      // TODO: implement build
      return Column(
        children: <Widget>[
          RadioListTile(
            value: 0,
            title: Text("已婚"),
            subtitle: Text("包括离异"),
            // secondary: Icon(Icons.airline_seat_legroom_extra),
            groupValue: _radioValue,
            selected: _radioValue==0,
            onChanged: (value){
              setState(() {
                _radioValue=value;
                // print(value);
              });
            },
          ),
          RadioListTile(
            value: 1,
            title: Text("未婚"),
            subtitle: Text("同居不算已婚"),
            groupValue: _radioValue,
            selected: _radioValue==1,
            onChanged: (value){
              setState(() {
                _radioValue=value;
                // print(value);
              });
            },
          )
        ],
      );
    }
}
class mySwitch extends StatefulWidget{
  @override
    mySwitchState createState() {
      // TODO: implement createState
      return mySwitchState();
    }
}
class mySwitchState extends State<mySwitch>{
  bool _switchValue=false;
  @override
    Widget build(BuildContext context) {
      // TODO: implement build
      return SwitchListTile(
        title: Text("全景杜比音效"),
        subtitle: Text("播放音乐自动开启"),
        // secondary: Icon(Icons.library_music),
        secondary:Icon(_switchValue?Icons.visibility:Icons.visibility_off),
        value: _switchValue,
        onChanged: (value){
          setState(() {
                      _switchValue=value;
                    });
        },
        selected: _switchValue,
      );
    }
}
class mySlide extends StatefulWidget{
  @override
    mySlideState createState() {
      // TODO: implement createState
      return mySlideState();
    }
}
class mySlideState extends State<mySlide>{
  var _slideValue=10.0;
  @override
    Widget build(BuildContext context) {
      // TODO: implement build
      return Column(
        children: <Widget>[
          Slider(
        value: _slideValue,
        min: 0.0,
        max: 100.0,
        divisions: 10,
        label:'$_slideValue',
        onChanged: (value){
          setState(() {
                      _slideValue=value;
                    });
        },
      ),
      Text(_slideValue.toString())
        ],
      );
    }
}